﻿/// File: DbiSupportObjects.cs 
/// Date: 03/15/2012
/// Author: Phil Allison (stoneguard@gmail.com)
/// Purpose: These are general support functions wrapped within a class in the base namespace for this library
/// 
/// copyright (c) 2001-2012, Phil Allison. Under the MIT License http://www.opensource.org/licenses/mit-license.php  
/// Feel free to reuse and modify this code as long as credit is given to the original author.
/// Modified code must be noted in this section.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace sgsBase
{
	[Serializable]
	public class DbConditionalView
	{
		public string View = "";
		public string SecurityId = "";
		//public SecLevel Condition = SecLevel.Hidden;
	}
	/// <summary>
	/// DbThreadHolder - this class is used to hold the databse connectors for a thread. 
	/// </summary>
	/// As multiple threads may be running at the same time, this class is used to track database connections for each thread.
	public class DbThreadHolder
	{
		public int ThreadId = 0;
		public Dictionary<string, DbConnector> DbConnectors;
	}

	/// <summary>
	/// DbConnector - Database connection class holding a connector to the database.
	/// </summary>
	/// this connector will get reused as opposed to allocating many of them, hogging resources and creating overhead
	public class DbConnector
	{
		public string ConnectionString = "";
		private SqlConnection m_connection = null;
		private SqlTransaction m_transaction = null;

		public SqlConnection Connection
		{
			get
			{
				if (m_connection == null)
				{
					m_connection = new SqlConnection(ConnectionString);
				}

				return m_connection;
			}
			set { m_connection = value; }
		}

		public SqlTransaction Transaction
		{
			get { return m_transaction; }
			set { m_transaction = value; }
		}
	}
}
